<?php

namespace C\S\Casher;

use C\L\Service;
use C\M\Payment as PaymentModel;
use Phalcon\Paginator\Factory;

class Payment extends Service
{
    protected function setModel()
    {
        $this->model = new PaymentModel();
    }

  /**
   * 列出支付渠道
   *
   * @param int $currentPage
   * @param int $perPage
   * @return mixed
   **/
    public function paginate($currentPage, $perPage)
    {
        $builder = PaymentModel::query()
        ->orderBy("id ASC")
        ->createBuilder();

        return $this->paginateByBuilder($builder, $currentPage, $perPage);
    }

  /**
   * 查看支付渠道
   *
   * @param int $id
   * @return mixed
   **/
    public function view($id)
    {
        return PaymentModel::findById($id);
    }

  /**
   * 添加支付渠道
   *
   * @param array $params
   * @return mixed
   **/
    public function store($params)
    {
        $payment = new PaymentModel();

        return $payment->save($params)
        ? $payment
        : false;
    }

  /**
   * 更新支付渠道
   *
   * @param int $id
   * @param array $params
   * @return mixed
   **/
    public function newUpdate($id, $params)
    {
        $payment = PaymentModel::findById($id);

        if (!$payment) {
            return false;
        }

        return $payment->save($params)
        ? $payment
        : false;
    }

  /**
   * 删除支付渠道
   *
   * @param int $id
   * @param array $params
   * @return mixed
   **/
    public function delete($id)
    {
        $payment = PaymentModel::findById($id);

        if (!$payment) {
            return false;
        }

        return $payment->delete();
    }
}
